import dotenv
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_community.tools.openai_dalle_image_generation import OpenAIDALLEImageGenerationTool
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field
from langchain_community.tools import GoogleSerperRun

dotenv.load_dotenv()

class GoogleSerperSchema(BaseModel):
    query: str = Field(description="执行谷歌搜索的查询语句")


google_serper = GoogleSerperRun(
    name="google_serper",
    description=(
        "一个低成本的谷歌搜索工具"
        "当你想要回答有关问题的时候，可以调用该工具"
        "该工具的输入是搜索查询语句"
    ),
    api_wrapper=GoogleSerperAPIWrapper()
)

dalle = OpenAIDALLEImageGenerationTool(
    name = "openai-dalle",
    api_wrapper = DallEAPIWrapper(model="dall-e-3")
)

tools = [google_serper,dalle]

prompt = ChatPromptTemplate.from_messages([
    ("system","你是一个功能强大的助手"),
    ("placeholder","{chat_history}"),
    ("human","{input}"),
    ("placeholder","{agent_scratchpad}"),
])

# 创建模型
llm = ChatOpenAI(model="gpt-4o-mini")

agent = create_tool_calling_agent(
    prompt=prompt,
    llm=llm,
    tools=tools,

)

agent_executor = AgentExecutor(agent=agent,tools=tools,verbode=True)

print(agent_executor.invoke({"input":"今天港股表现怎么样"}))